package com.cml.domain.entity;

import com.cml.common.dto.entity.Message;
import com.cml.infrastructure.ClientQueueManage;

import java.util.UUID;

/**
 * 姓名：陈茂林
 * 时间：2023/10/17 9:09
 * 描述：
 */
public class Session {
    private String sessionId;

    private boolean isClose=false;

    public boolean isClose() {
        return isClose;
    }

    public void setClose(boolean close) {
        isClose = close;
    }

    private Thread clientIOThread;

    public Thread getClientIOThread() {
        return clientIOThread;
    }

    public void setClientIOThread(Thread clientIOThread) {
        this.clientIOThread = clientIOThread;
    }

    public String getSessionId() {
        return sessionId;
    }

    public void setSessionId(String sessionId) {
        this.sessionId = sessionId;
    }

    public boolean sendMessage(Message message) throws InterruptedException {
        if(!this.isClose){
            ClientQueueManage.pushSendMessageMessage(sessionId,message);
            return true;
        }
        return false;
    }

    public Session(){
        sessionId = UUID.randomUUID().toString();
    }
}
